// JavaScript Document

setUserForms = function() {
  var section = $("#profile-edit");
  if ($(section).length > 0){
    $("a[href=#identifiants]").click(editUserIdent);
    $("a[href=#donnees-personnelles]").click(editUserData);
    $("a[href=#abonements]").click(editUserMailing);
  }
}

requiredSpan = function() {
  var span = document.createElement("span");
  $(span).attr("class","required");
  $(span).text("*");
  return span;
}

setUsersBankAccount = function() {
  var section = $("#account");
  if ($(section).length > 0){
    $("a[href=#compte-bancaire]").click(function() {
      editUserBankAccount(false);
    });
    $("a[href=#creer-compte]").click(function() {
      editUserBankAccount(true);
    });
  }
}

validateUserIdents = function() {
  alert('Fonctionnalité indisponible.');
//  var vlogin = $("input[name=login]").val();
//  var vemail = $("input[name=email]").val();
//  var vpassword = $("input[name=password]").val();
//  var vnpassword = $("input[name=npassword]").val();
//  var vcnpassword = $("input[name=cnpassword]").val();
//
//  $.post("/profil/update-ident-profile.htm", {
//    login: vlogin,
//    email: vemail,
//    password: vpassword,
//    npassword: vnpassword,
//    cnpassword: vcnpassword
//  }, function(xml){
//    //      var r = $(xml).find("result").text() == "1";
//    //      if (r) alert("okkkk");
//    //      else   alert("echec");
//    });
}
cancelUserIdents = function() {
  var pseudo = $("input[name=login]").val();
  var email = $("input[name=email]").val();

  //Pseudo
  var span = document.createElement("span");
  $(span).append(pseudo);

  var p1 = document.createElement("p");
  $(p1).text("Pseudo :");
  $(p1).append(span);

  //email
  span = document.createElement("span");
  $(span).append(email);

  var p2 = document.createElement("p");
  $(p2).text("Email :");
  $(p2).append(span);

  //lien
  var a = document.createElement("a");
  $(a).attr("id","identifiant");
  $(a).attr("href","#identifiants");
  $(a).text("Éditer");
  $(a).click(editUserIdent);

  var strong = document.createElement("strong");
  $(strong).append(a);

  var p3 = document.createElement("p");
  $(p3).append(strong);

  //End
  $("#profile-edit").empty();

  var pe= $("#profile-edit");
  $(pe).append(p1);
  $(pe).append(p2);
  $(pe).append(p3);
}

validateUserData = function() {
  alert('Fonctionnalité indisponible.');
//  var vlogin = $("input[name=login]").val();
//  var vvlogin = $("#profile-edit p:first span:first");
//  var vfirstname = $("input[name=firstName]").val();
//  var vlastname = $("input[name=lastName]").val();
//  var vaddress0 = $("input[name=address0]").val();
//  var vaddress1 = $("input[name=address1]").val();
//  var vaddress2 = $("input[name=address2]").val();
//  var vzipcode = $("input[name=zipCode]").val();
//  var vcity = $("input[name=city]").val();
//  var vcountry = $("input[name=country]").val();
//  var vbirthdatewrapper = $("input[name=birthDateWrapper]").val();
//  var vphonehome = $("input[name=phoneHome]").val();
//  var vphonegsm = $("input[name=phoneGsm]").val();
//
//  if (vlogin == null){
//    var vvvlogin = vvlogin
//  } else{
//    vvvlogin = vlogin
//  }
//  alert(vvvlogin);
//
//  $.post("/profil/update-ident-data.htm", {
//    login: vvvlogin,
//    firstname: vfirstname,
//    lastname:  vlastname,
//    address0: vaddress0,
//    address1: vaddress1,
//    address2: vaddress2,
//    zipcode: vzipcode,
//    city: vcity,
//    country: vcountry,
//    birthdatewrapper: vbirthdatewrapper,
//    phonehome: vphonehome,
//    phonegsm: vphonegsm
//  }, function(xml){
//    var r = $(xml).find("result").text() == "1";
//    if (r) alert("ok");
//    else   alert("echec");
//  });
}

cancelUserData = function() {
  var firstname = $("input[name=firstName]").val();
  var lastname = $("input[name=lastName]").val();
  var address0 = $("input[name=address0]").val();
  var address1 = $("input[name=address1]").val();
  var address2 = $("input[name=address2]").val();
  var zipcode = $("input[name=zipCode]").val();
  var city = $("input[name=city]").val();
  var country = $("input[name=country]").val();
  var birthdatewrapper = $("input[name=birthDateWrapper]").val();
  var phonehome = $("input[name=phoneHome]").val();
  var phonegsm = $("input[name=phoneGsm]").val();

  //Lastname
  var span = document.createElement("span");
  $(span).append(lastname);

  var p0 = document.createElement("p");
  $(p0).text("Nom :");
  $(p0).append(span);

  //Firstname
  span = document.createElement("span");
  $(span).append(firstname);

  var p1 = document.createElement("p");
  $(p1).text("Prénom :");
  $(p1).append(span);

  //Address
  span = document.createElement("span");
  $(span).append(address0);

  var span1 = document.createElement("span");
  $(span).append(address1);

  var span2 = document.createElement("span");
  $(span).append(address2);

  var p2 = document.createElement("p");
  $(p2).text("Adresse :");
  $(p2).append(span);
  $(p2).append(span1);
  $(p2).append(span2);

  span = document.createElement("span");
  $(span).append(zipcode);

  span1 = document.createElement("span");
  $(span).append(city);

  span2 = document.createElement("span");
  $(span).append(country);

  var p3 = document.createElement("p");
  $(p3).append(span);
  $(p3).append(span1);
  $(p3).append(span2);

  //birthdate
  span = document.createElement("span");
  $(span).append(birthdatewrapper);

  var p4 = document.createElement("p");
  $(p4).text("Date de naissance :");
  $(p4).append(span)

  //Phonehome
  span = document.createElement("span");
  $(span).append(phonehome);

  var p5 = document.createElement("p");
  $(p5).text("Téléphone fixe :");
  $(p5).append(span);

  //Phonegsm
  span = document.createElement("span");
  $(span).append(phonegsm);

  var p6 = document.createElement("p");
  $(p6).text("Téléphone mobile :");
  $(p6).append(span);

  //lien
  var a = document.createElement("a");
  $(a).attr("id","donnees-perso");
  $(a).attr("href","#donnees-personnelles");
  $(a).text("Éditer");
  $(a).click(editUserData);

  var strong = document.createElement("strong");
  $(strong).append(a);

  var p7 = document.createElement("p");
  $(p7).append(strong);

  //End
  $("#profile-pdate").empty();

  var pe= $("#profile-pdate");
  $(pe).append(p0);
  $(pe).append(p1);
  $(pe).append(p2);
  $(pe).append(p3);
  $(pe).append(p4);
  $(pe).append(p5);
  $(pe).append(p6);
  $(pe).append(p7);
}

validateUserMail = function() {
  alert('Fonctionnalité indisponible.');
//  var vlogin = $("input[name=login]").val();
//  var vacceptNewsletterSite = $("input[name=acceptNewsletterSite]").val();
//  var vacceptNewsletterPartners = $("input[name=acceptNewsletterPartners]").val();
//  $.post("/profil/update-ident-mailing.htm", {
//    login: vlogin,
//    acceptNewsletterSite: vacceptNewsletterSite,
//    acceptNewsletterPartners: vacceptNewsletterPartners
//  }, function(xml){
//    var r = $(xml).find("result").text() == "1";
//    if (r) alert("ok");
//    else   alert("echec");
//  });
}

cancelUserMail = function() {
  var acceptNewsletterSite = $("input[name=acceptNewsletterSite]:checked");
  var acceptNewsletterPartners = $("input[name=acceptNewsletterPartners]:checked");

  var p2 = document.createElement("p");
  if($(acceptNewsletterPartners).length == 1) {
    $(p2).text("J'ai accepté de recevoir les newsletters des partenaires de bet-on-tv.com");
  }else{
    $(p2).text("Je n'ai pas accepté de recevoir les newsletters des partenaires de bet-on-tv.com");
  }
  var p1 = document.createElement("p");
  if($(acceptNewsletterSite).length == 1) {
    $(p1).text("J'ai accepté de recevoir les newsletters de bet-on-tv.com");
  }else{
    $(p1).text("Je n'ai pas accepté de recevoir les newsletters de bet-on-tv.com");
  }

  //lien
  var a = document.createElement("a");
  $(a).attr("id","abonements");
  $(a).attr("href","#abonements");
  $(a).text("Éditer");
  $(a).click(editUserMailing);

  var strong = document.createElement("strong");
  $(strong).append(a);

  var p3 = document.createElement("p");
  $(p3).append(strong);

  //End
  $("#profile-mailing").empty();

  var pe= $("#profile-mailing");
  $(pe).append(p2);
  $(pe).append(p1);
  $(pe).append(p3);
}


changePassword = function() {
  //old password
  var ex = $("fieldset").children("p:nth-child(4)").children("label");
  $(ex).text("Ancien mot de passe ");
  $(ex).append(requiredSpan());
  $(ex).append(" :");

  $("fieldset").children("p:nth-child(4)").children("a").remove();

  //new password
  var label = document.createElement("label");
  $(label).text("Nouveau mot de passe ");
  $(label).append(requiredSpan());
  $(label).append(" :");

  var input = document.createElement("input");
  $(input).attr("id", "password");
  $(input).attr("name", "npassword");
  $(input).attr("required", "required");
  $(input).attr("type", "password");
  $(input).attr("value","");

  var p1 = document.createElement("p");
  $(p1).append(label);
  $(p1).append(input);

  //check new password
  label = document.createElement("label");
  $(label).text("Confirmation du mot de passe ");
  $(label).append(requiredSpan());
  $(label).append(" :");

  input = document.createElement("input");
  $(input).attr("id", "password");
  $(input).attr("name", "cnpassword");
  $(input).attr("required", "required");
  $(input).attr("type", "password");
  $(input).attr("value","");

  var p2 = document.createElement("p");
  $(p2).append(label);
  $(p2).append(input);

  var avButton = $(".submit-button:first");
  $(avButton).before(p1);
  $(avButton).before(p2);
}


editUserIdent = function() {
  var pseudo = $("#profile-edit > p:first span").text();
  var email = $("#profile-edit > p:nth-child(2) span").text();

  var legend = document.createElement("legend");
  $(legend).text("Identifiants");

  //Pseudo
  var label = document.createElement("label");
  $(label).text("Pseudo :");

  var input = document.createElement("input");
  $(input).attr("readonly", "readonly");
  $(input).attr("id", "login");
  $(input).attr("name", "login");
  $(input).attr("required", "required");
  $(input).attr("type", "text");
  $(input).attr("value",pseudo);

  var p1 = document.createElement("p");
  $(p1).append(label);
  $(p1).append(input);

  //email
  label = document.createElement("label");
  $(label).text("Courriel ");
  $(label).append(requiredSpan());
  $(label).append(" :");

  input = document.createElement("input");
  $(input).attr("id", "email");
  $(input).attr("name", "email");
  $(input).attr("required", "required");
  $(input).attr("type", "email");
  $(input).attr("value",email);

  var p2 = document.createElement("p");
  $(p2).append(label);
  $(p2).append(input);

  //mot de passe
  label = document.createElement("label");
  $(label).text("Confirmer mot de passe ");
  $(label).append(requiredSpan());
  $(label).append(" :");

  input = document.createElement("input");
  $(input).attr("id", "password");
  $(input).attr("name", "password");
  $(input).attr("required", "required");
  $(input).attr("type", "password");
  $(input).attr("value","");

  var a = document.createElement("a");
  $(a).attr("href","#changer-mot-de-passe");
  $(a).append("  Changer mon mot de passe")
  $(a).click(changePassword);

  var p3 = document.createElement("p");
  $(p3).append(label);
  $(p3).append(input);
  $(p3).append(a);

  //End
  var fieldset = document.createElement("fieldset");
  $(fieldset).append(legend);
  $(fieldset).append(p1);
  $(fieldset).append(p2);
  $(fieldset).append(p3);
  $(fieldset).append(createButton("Annuler", cancelUserIdents ));
  $(fieldset).append(createButton("Valider", validateUserIdents ));

  var form = document.createElement("form");
  $(form).append(fieldset);

  $("#profile-edit").empty();
  $("#profile-edit").append(form);
}


editUserData = function() {
  var data    = $("#profile-pdate > p:first");

  var lastname  = $(data).children("span").text();
  data = $(data).next();
  var firstname = $(data).children("span").text();
  data = $(data).next();
  var address0  = $(data).children("span:first").text();
  var address1  = $(data).children("span:nth-child(2)").text();
  var address2  = $(data).children("span:last").text();
  data = $(data).next();
  var zipcode   = $(data).children("span:first").text();
  var city      = $(data).children("span:nth-child(2)").text();
  var country   =$(data).children("span:last").text();
  data = $(data).next();
  var birthdate = $(data).children("span").text();
  data = $(data).next();
  var phonehome =$(data).children("span").text();
  data = $(data).next();
  var phonegsm  = $(data).children("span").text();
  data = $(data).next();

  var legend = document.createElement("legend");
  $(legend).text("Données personnelles");

  //Nom
  label = document.createElement("label");
  $(label).text("Nom ");
  $(label).append(requiredSpan());
  $(label).append(" :");

  input = document.createElement("input");
  $(input).attr("id", "lastName");
  $(input).attr("name", "lastName");
  $(input).attr("required", "required");
  $(input).attr("type", "text");
  $(input).attr("value",lastname);

  var p1 = document.createElement("p");
  $(p1).append(label);
  $(p1).append(input);

  //Prénom
  var label = document.createElement("label");
  $(label).text("Prénom :");
  $(label).append(requiredSpan());
  $(label).append(" :");

  var input = document.createElement("input");
  $(input).attr("id", "firstName");
  $(input).attr("name", "firstName");
  $(input).attr("required", "required");
  $(input).attr("type", "text");
  $(input).attr("value",firstname);

  var p2 = document.createElement("p");
  $(p2).append(label);
  $(p2).append(input);

  //Addresse0
  label = document.createElement("label");
  $(label).text("Addresse ");
  $(label).append(requiredSpan());
  $(label).append(" :");

  input = document.createElement("input");
  $(input).attr("id", "address0");
  $(input).attr("name", "address0");
  $(input).attr("required", "required");
  $(input).attr("type", "text");
  $(input).attr("value",address0);

  var p3 = document.createElement("p");
  $(p3).append(label);
  $(p3).append(input);

  //Addresse1
  label = document.createElement("label");
  $(label).text("Addresse ");
  $(label).append(" :");

  input = document.createElement("input");
  $(input).attr("id", "address1");
  $(input).attr("name", "address1");
  $(input).attr("type", "text");
  $(input).attr("value",address1);

  var p4 = document.createElement("p");
  $(p4).append(label);
  $(p4).append(input);

  //Addresse2
  label = document.createElement("label");
  $(label).text("Addresse ");
  $(label).append(" :");

  input = document.createElement("input");
  $(input).attr("id", "address2");
  $(input).attr("name", "address2");
  $(input).attr("type", "text");
  $(input).attr("value",address2);

  var p5 = document.createElement("p");
  $(p5).append(label);
  $(p5).append(input);

  //code postal
  label = document.createElement("label");
  $(label).text("Code postal ");
  $(label).append(requiredSpan());
  $(label).append(" :");

  input = document.createElement("input");
  $(input).attr("id", "zipCode");
  $(input).attr("name", "zipCode");
  $(input).attr("required", "required");
  $(input).attr("type", "text");
  $(input).attr("value",zipcode);

  var p6 = document.createElement("p");
  $(p6).append(label);
  $(p6).append(input);

  //Ville
  label = document.createElement("label");
  $(label).text("Ville ");
  $(label).append(requiredSpan());
  $(label).append(" :");

  input = document.createElement("input");
  $(input).attr("id", "city");
  $(input).attr("name", "city");
  $(input).attr("required", "required");
  $(input).attr("type", "text");
  $(input).attr("value",city);

  var p7 = document.createElement("p");
  $(p7).append(label);
  $(p7).append(input);

  //Pays
  label = document.createElement("label");
  $(label).text("Pays ");
  $(label).append(requiredSpan());
  $(label).append(" :");

  input = document.createElement("input");
  $(input).attr("id", "country");
  $(input).attr("name", "country");
  $(input).attr("required", "required");
  $(input).attr("type", "text");
  $(input).attr("value",country);

  var p8 = document.createElement("p");
  $(p8).append(label);
  $(p8).append(input);

  //date naissance
  label = document.createElement("label");
  $(label).text("Date de naissance ");
  $(label).append(requiredSpan());
  $(label).append(" :");

  input = document.createElement("input");
  $(input).attr("id", "birthDateWrapper");
  $(input).attr("name", "birthDateWrapper");
  $(input).attr("required", "required");
  $(input).attr("type", "date");
  $(input).attr("value",birthdate);

  var p9 = document.createElement("p");
  $(p9).append(label);
  $(p9).append(input);

  //phoneHome
  label = document.createElement("label");
  $(label).text("Téléphone fixe ");
  $(label).append(" :");

  input = document.createElement("input");
  $(input).attr("id", "phoneHome");
  $(input).attr("name", "phoneHome");
  $(input).attr("type", "text");
  $(input).attr("value",phonehome);

  var p10 = document.createElement("p");
  $(p10).append(label);
  $(p10).append(input);

  //phoneGsm
  label = document.createElement("label");
  $(label).text("Téléphone portable ");
  $(label).append(" :");

  input = document.createElement("input");
  $(input).attr("id", "phoneGsm");
  $(input).attr("name", "phoneGsm");
  $(input).attr("type", "text");
  $(input).attr("value",phonegsm);

  var p11 = document.createElement("p");
  $(p11).append(label);
  $(p11).append(input);

  //End
  var fieldset = document.createElement("fieldset");
  $(fieldset).append(legend);
  $(fieldset).append(p1);
  $(fieldset).append(p2);
  $(fieldset).append(p3);
  $(fieldset).append(p4);
  $(fieldset).append(p5);
  $(fieldset).append(p6);
  $(fieldset).append(p7);
  $(fieldset).append(p8);
  $(fieldset).append(p9);
  $(fieldset).append(p10);
  $(fieldset).append(p11);

  $(fieldset).append(createButton("Annuler", cancelUserData ));
  $(fieldset).append(createButton("Valider", validateUserData ));

  var form = document.createElement("form");
  $(form).append(fieldset);

  $("#profile-pdate").empty();
  $("#profile-pdate").append(form);
}

editUserMailing = function() {
  var legend = document.createElement("legend");
  $(legend).text("Abonements");
  //newsLetter partenaires
  label = document.createElement("label");
  $(label).text("J'accepte de recevoir la newsletter des partenaires de bet-on-tv.com");

  input = document.createElement("input");
  $(input).attr("id", "acceptNewsletterPartners1");
  $(input).attr("name", "acceptNewsletterPartners")
  $(input).attr("type", "checkbox");
  $(input).attr("value",true);

  input2 = document.createElement("input");
  $(input2).attr("type", "hidden");
  $(input2).attr("name", "acceptNewsletterPartners");
  $(input2).attr("value", "on");

  var p2 = document.createElement("p");
  $(p2).append(input);
  $(p2).append(input2);
  $(p2).append(label);

  //newsLetter site
  label = document.createElement("label");
  $(label).text("J'accepte de recevoir la newsletter de bet-on-tv.com");

  input = document.createElement("input");
  $(input).attr("id", "acceptNewsletterSite1");
  $(input).attr("name", "acceptNewsletterSite")
  $(input).attr("type", "checkbox");
  $(input).attr("value",true);

  var input2 = document.createElement("input");
  $(input2).attr("type", "hidden");
  $(input2).attr("name", "_acceptNewsletterSite");
  $(input2).attr("value", "on");

  var p1 = document.createElement("p");
  $(p1).append(input);
  $(p1).append(input2);
  $(p1).append(label);

  //End
  var fieldset = document.createElement("fieldset");
  $(fieldset).append(legend);
  $(fieldset).append(p2);
  $(fieldset).append(p1);

  $(fieldset).append(createButton("Annuler", cancelUserMail));
  $(fieldset).append(createButton("Valider", validateUserMail));

  var form = document.createElement("form");
  $(form).append(fieldset);

  $("#profile-mailing").empty();
  $("#profile-mailing").append(form);
}

editUserBankAccount = function(isNew){
  var legend = document.createElement("legend");
  $(legend).text("Compte Bancaire");

  var data = $("#account > p:first");
  var userId = $(data).text();
  var cryptogramme = "";
  var date = "";
  var type = "";
  var numero = "";
  var proprietaire = "";
  if (!isNew) {
    data = $(data).next();
    proprietaire = $(data).children("span").text();
    data = $(data).next();
    type = $(data).children("span").text();
    data = $(data).next();
    numero = $(data).children("span").text();
    data = $(data).next();
    date = $(data).children("span").text();
    data = $(data).next();
    cryptogramme = $(data).children("span").text();
    data = $(data).next();
  }
  
  //proprietaire
  var label = document.createElement("label");
  $(label).text("Nom du propriétaire ");
  $(label).append(requiredSpan());
  $(label).append(" :");

  var input = document.createElement("input");
  if (!isNew) $(input).attr("readonly", "readonly");
  $(input).attr("name", "cardName");
  $(input).attr("required", "required");
  $(input).attr("type", "text");
  $(input).attr("value",proprietaire);

  var p1 = document.createElement("p");
  $(p1).append(label);
  $(p1).append(input);

  //type
  label = document.createElement("label");
  $(label).text("Type de carte ");
  $(label).append(requiredSpan());
  $(label).append(" :");

  input = document.createElement("input");
  if (!isNew) $(input).attr("readonly", "readonly");
  $(input).attr("name", "name");
  $(input).attr("required", "required");
  $(input).attr("type", "text");
  $(input).attr("value",type);

  var p2 = document.createElement("p");
  $(p2).append(label);
  $(p2).append(input);

  //numero
  label = document.createElement("label");
  $(label).text("Numéro de la carte ");
  $(label).append(requiredSpan());
  $(label).append(" :");

  input = document.createElement("input");
  if (!isNew) $(input).attr("readonly", "readonly");
  $(input).attr("name", "cardNumber");
  $(input).attr("required", "required");
  $(input).attr("maxlength", "16");
  $(input).attr("type", "text");
  $(input).attr("value",numero);

  var p3 = document.createElement("p");
  $(p3).append(label);
  $(p3).append(input);

  //date
  label = document.createElement("label");
  $(label).text("Date d'expiration ");
  $(label).append(requiredSpan());
  $(label).append(" :");

  input = document.createElement("input");
  if (!isNew) $(input).attr("readonly", "readonly");
  $(input).attr("name", "cardExpirationDate");
  $(input).attr("required", "required");
  $(input).attr("type", "month");
  $(input).attr("value",date);

  var p4 = document.createElement("p");
  $(p4).append(label);
  $(p4).append(input);

  //cryptogramme
  label = document.createElement("label");
  $(label).text("Cryptogramme ");
  $(label).append(requiredSpan());
  $(label).append(" :");

  input = document.createElement("input");
  if (!isNew) $(input).attr("readonly", "readonly");
  $(input).attr("name", "cardCryptogram");
  $(input).attr("required", "required");
  $(input).attr("type", "text");
  $(input).attr("maxlength", "3");
  $(input).attr("value",cryptogramme);

  var p5 = document.createElement("p");
  $(p5).append(label);
  $(p5).append(input);

  input = document.createElement("input");
  $(input).attr("name", "userId");
  $(input).attr("type", "hidden");
  $(input).attr("value", userId);

  //End
  var fieldset = document.createElement("fieldset");
  $(fieldset).append(legend);
  $(fieldset).append(p2);
  $(fieldset).append(p1);
  $(fieldset).append(p3);
  $(fieldset).append(p4);
  $(fieldset).append(p5);
  $(fieldset).append(input);

  if (isNew) {
    $(fieldset).append(createButton("Valider", createCard));
  } else {
    $(fieldset).append(createButton("Annuler", cancelCardEdit));
    $(fieldset).append(createButton("Supprimer", deleteCard));
  }

  var form = document.createElement("form");
  $(form).append(fieldset);

  $("#account").empty();
  $("#account").append(form);
}

cancelCardEdit = function(){
  var userId = $("input[name=userId]").val();
  var proprietaire = $("input[name=cardName]").val();
  var type = $("input[name=name]").val();
  var numero = $("input[name=cardNumber]").val();
  var date = $("input[name=cardExpirationDate]").val();
  var crypto = $("input[name=cardCryptogram]").val();

  var p = document.createElement("p");
  $(p).addClass("hidden");
  $(p).append(userId);

  //Nom
  span = document.createElement("span");
  $(span).append(proprietaire);

  var p0 = document.createElement("p");
  $(p0).text("Nom du propriétaire : :");
  $(p0).append(span);

  //type
  span = document.createElement("span");
  $(span).append(type);

  var p1 = document.createElement("p");
  $(p1).text("Type de carte :");
  $(p1).append(span);

  //#card
  span = document.createElement("span");
  $(span).append(numero);

  var p2 = document.createElement("p");
  $(p2).text("Numéro de la carte :");
  $(p2).append(span);

  //dateExp
  span = document.createElement("span");
  $(span).append(date);

  var p3 = document.createElement("p");
  $(p3).text("ate d'expiration :");
  $(p3).append(span);

  //crypto
  span = document.createElement("span");
  $(span).append(crypto);

  var p4 = document.createElement("p");
  $(p4).text("Cryptogramme :");
  $(p4).append(span);

  //lien
  var a = document.createElement("a");
  $(a).attr("id","account");
  $(a).attr("href","#compte-bancaire");
  $(a).text("Gestion de mon compte");
  $(a).click(editUserBankAccount);

  var strong = document.createElement("strong");
  $(strong).append(a);

  var p5 = document.createElement("p");
  $(p5).append(strong);

  //End
  $("#account").empty();

  var pe= $("#account");
  $(pe).append(p);
  $(pe).append(p0);
  $(pe).append(p1);
  $(pe).append(p2);
  $(pe).append(p3);
  $(pe).append(p4);
  $(pe).append(p5);
}

deleteCard = function() {
  var userId = $("input[name=userId]").val();

  $.post("/profil/delete-card.htm", {
    uid:userId
  },function(xml){
    var r = $(xml).find("result").text() == "1";
    if (r) window.location = "comptes.htm";
    else   alert("Impossible de suprrimer cette méthode le paiement.");
  });
}

createCard = function(){
  var userId = $("input[name=userId]").val();
  var vproprietaire = $("input[name=cardName]").val();
  var vtype = $("input[name=name]").val();
  var vnumero = $("input[name=cardNumber]").val();
  var vdate = $("input[name=cardExpirationDate]").val();
  var vcrypto = $("input[name=cardCryptogram]").val();
  
  $.post("/profil/create-card.htm", {
    uid: userId,
    name: vtype,
    cardName: vproprietaire,
    cardNumber: vnumero,
    cardExpirationDate: vdate,
    cardCryptogram: vcrypto
  }, function(xml){
    var r = $(xml).find("result").text() == "1";
    if (r) window.location = "comptes.htm";
    else   alert("Impossible d'ajouter cette méthode le paiement.");
  });
}